package org.hzero.business.workflow.builder.director;

import org.activiti.rest.service.api.engine.variable.RestVariable;
import org.activiti.rest.service.api.runtime.process.ProcessInstanceCreateRequest;
import org.hzero.business.workflow.builder.KnifeWorkflowRequestBuilder;

/**
 * @ClassName: AtnProcessInstanceDirector
 * @Description: 工作流request参数中介者类，负责与开发者进行交互
 * @author: tianhao.luo@hand-china.com
 * @date: 2020/9/4  15:26
 */
public class KnifeWorkflowRequestDirector {

    /**
     * request参数建造者父类接口
     */
    private KnifeWorkflowRequestBuilder knifeWorkflowRequestBuilder;


    public KnifeWorkflowRequestDirector(KnifeWorkflowRequestBuilder knifeWorkflowRequestBuilder) {
        this.knifeWorkflowRequestBuilder = knifeWorkflowRequestBuilder;
    }

    /**
     * 构造流程变量
     * @param fieldName 属性名称
     * @param value 属性值
     * @param valueType 属性类型
     * @param restVariableScope 变量范围对象
     * @return 中介者对象
     */
    public KnifeWorkflowRequestDirector createRestVariable(String fieldName, Object value, String valueType, RestVariable.RestVariableScope restVariableScope){
        knifeWorkflowRequestBuilder.buildVariable(fieldName, value, valueType, restVariableScope);
        return this;

    }

    /**
     * 生成request请求对象
     * @param processDefinitionKey 流程定义key
     * @param businessKey 业务主键
     * @return request请求对象
     */
    public ProcessInstanceCreateRequest buildRequest(String processDefinitionKey,String businessKey){
        return knifeWorkflowRequestBuilder.buildBusinessKey(businessKey).buildProcessDefinitionKey(processDefinitionKey).build();

    }
}
